<?php 

use think\facade\Route;

Route::group("coupon", function (){
    // 根据店铺ID获取优惠券列表，接收参数：shop_id
    Route::get("getByStoreId/:shopId", "CouponController/getCouponsByShopId");

    // 根据用户ID和优惠券ID检查用户是否领取过优惠券，接收参数：user_id, coupon_id
    Route::post("checkUserCoupon", "CouponController/checkUserCoupon");

    // 领取优惠券，接收参数：user_id, coupon_id
    Route::get("receive/:userId/:couponId", "CouponController/receiveCoupon");

    // 获取用户可用的优惠券
    Route::get("getAvailableCoupon/:userId/:goodsId", "CouponController/getAvailableCoupon")
        ->pattern([
            'goodsId' => '[\w\.\-]+'    // 允许字母、数字、下划线、短横线
        ]);

    // 使用优惠券，接收参数：userId, couponId
    Route::put("useCoupon", "CouponController/useCoupon"); 

    // 获取用户所有优惠券，接收参数：userId
    Route::get("getAllByUserId/:userId", "CouponController/getUserCoupons");

    // 获取用户已使用的优惠券，接收参数：userId
    Route::get("getUsedByUserId/:userId", "CouponController/getUsedCoupons");

    // 根据优惠券ID查询优惠券信息，接收参数：couponId
    Route::get("getById/:couponId", "CouponController/getCouponById");
    
});